﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace PictureProcessing.Comm
{
    public class DateHandlecs
    {
        #region 复制文件
        /// <summary>
        /// 复制文件
        /// </summary>
        /// <param name="dir1">要复制的文件的路径已经全名(包括后缀)</param>
        /// <param name="dir2">目标位置,并指定新的文件名</param>
        public static void CopyFile(string dir1, string dir2)
        {
            dir1 = dir1.Replace("/", "\\");
            dir2 = dir2.Replace("/", "\\");
            if (File.Exists(dir1))
            {
                File.Copy(dir1, dir2, true);
            }
        }
        #endregion


        #region 复制文件夹
        /// <summary>
        /// 复制文件夹(屏蔽递归)
        /// </summary>
        /// <param name="varFromDirectory">源文件夹路径</param>
        /// <param name="varToDirectory">目标文件夹路径</param>
        public static void CopyFolder(string varFromDirectory, string varToDirectory = null)
        {
            if (!DirFile.IsExistDirectory(varToDirectory))
            {
                Directory.CreateDirectory(varToDirectory);
            }


            if (!Directory.Exists(varFromDirectory)) return;

            string[] directories = Directory.GetDirectories(varFromDirectory);

            //if (directories.Length > 0)
            //{
            //    foreach (string d in directories)
            //    {
            //        CopyFolder(d, varToDirectory + d.Substring(d.LastIndexOf("\\")));
            //    }
            //}
            string[] files = Directory.GetFiles(varFromDirectory);
            if (files.Length > 0)
            {
                foreach (string s in files)
                {
                    File.Copy(s, varToDirectory + s.Substring(s.LastIndexOf("\\")), true);
                }
            }
        }
        #endregion

        #region
        /// <summary>
        /// 获取图片名称
        /// </summary>
        /// <param name="fullStr"></param>
        /// <returns></returns>
        public static string GetFileName(string fullStr) 
        {
            string aa = fullStr;
            string ss = aa.Substring(0, aa.LastIndexOf("\\"));
            int yy = aa.Length - ss.Length;
            string filename = aa.Substring(ss.Length + 1, aa.Length - ss.Length - 1);
            return filename;
        }
        #endregion
    }
}
